/*
 * ============================================================================
 *
 *       Filename:  log.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015年03月12日 15时18分02秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "log.h"

void pr_pkt(void *pkt, int len)
{
	if(LOG_DEBUG > debug)
		return;

	int i;
	unsigned char *_pkt = pkt;
	for(i = 0; i < len; i++) {
		sys_info("%02x ", _pkt[i]);
		if(!((i + 1) % 8)) sys_info("\t");
		if(!((i + 1) % 16)) sys_info("\n");
	}
	sys_info("\n");
}

void pr_md5(void *md5)
{
	if(LOG_DEBUG > debug)
		return;

	unsigned char *_md5 = md5;
	sys_info("md5: %02x%02x%02x%02x%02x%02x%02x%02x"
		"%02x%02x%02x%02x%02x%02x%02x%02x\n",
		(_md5)[0],  (_md5)[1],  (_md5)[2],  (_md5)[3], 
		(_md5)[4],  (_md5)[5],  (_md5)[6],  (_md5)[7],
		(_md5)[8],  (_md5)[9],  (_md5)[10], (_md5)[11],
		(_md5)[12], (_md5)[13], (_md5)[14], (_md5)[15]);
}

void pr_ipv4(struct sockaddr_in *addr)
{
	if(LOG_DEBUG > debug)
		return;

	char _buf[20];
	inet_ntop(AF_INET, &addr->sin_addr, _buf, 19);
	sys_info("address:%s, port:%d\n", _buf, ntohs(addr->sin_port)); 
}

void pr_mac(void *mac)
{
	if(LOG_DEBUG > debug)
		return;

	unsigned char *_mac = mac;
	sys_info("%02x:%02x:%02x:%02x:%02x:%02x\n",
		(_mac)[0], (_mac)[1], (_mac)[2],
		(_mac)[3], (_mac)[4], (_mac)[5]);
}

